#include "Button.h"

Button::Button(const Point2D& position, Uint32 background_color)
    : Rectangle(Point2D(100,50), position, background_color), 
      _handle_mouse_down(this,&Button::HandleMouseDown)
{
    MouseEvents::GetInstance()->OnMousePressed().Subscribe(&_handle_mouse_down);
}

Event<>& Button::OnClick()
{
    return _on_click;
}

void Button::HandleMouseDown(const Point2D& pos, int mouse_button)
{
    if
    (
        GetX() < pos.GetX() && pos.GetX() < GetX()+GetWidth() &&
        GetY() < pos.GetY() && pos.GetY() < GetY()+GetHeight() 
    )
        _on_click.Notify();
}
